#include "TrafficWid.h"
#include "ui_TrafficWid.h"

TrafficWid::TrafficWid(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::TrafficWid)
{
    ui->setupUi(this);
}

TrafficWid::~TrafficWid()
{
    delete ui;
}
void TrafficWid::new_label(){

    int count = get_count();

    for(int i=0;i<count;++i){
        QLabel *label=new QLabel();
        label->setSizePolicy(QSizePolicy::Preferred,QSizePolicy::Preferred);
        ui->horizontalLayout->addWidget(label);
        labelvec.push_back(label);
    }


}
void TrafficWid::set_value(int index,QString color,QString text,int value,bool display){

    QLabel *colorlabel=labelvec[index];
    QString setcolor="background-color:"+color;
    colorlabel->setStyleSheet(setcolor);

    if(display){
        colorlabel->setText(text);
        colorlabel->setAlignment(Qt::AlignHCenter);
        colorlabel->setFixedSize(value,30);
    }

}
//重写mousePressEvent事件,检测事件类型是不是点击了鼠标左键
void TrafficWid::mousePressEvent(QMouseEvent* event)
{
    //如果单击了就触发clicked信号
    if (event->button() == Qt::LeftButton)
    {
        //触发clicked信号
        emit clicked();
    }
    //将该事件传给父类处理
    QWidget::mousePressEvent(event);
}
